home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / rxdoscmd.zip / RXDOSMAC.ASM < prev    next >
Assembly Source File  |  1993-06-06  |  36KB  |  1,326 lines

  1.  
  2.  
  3.  
  4.  
  5.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  6.         ;  Macro Definitions                                            ;
  7.         ;...............................................................;
  8.  
  9.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  10.         ;  Real Time Dos Macro Include File                             ;
  11.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  12.         ;                                                               ;
  13.         ;  Macro include file.                                          ;
  14.         ;                                                               ;
  15.         ;                                                               ;
  16.         ;  (c) Copyright 1990, 1992. Api Software and Mike Podanoffsky  ;
  17.         ;      All Rights Reserved Worldwide.                           ;
  18.         ;                                                               ;
  19.         ;  This product is protected under copyright laws and  may not  ;
  20.         ;  be reproduced  in whole  or in part, in any form  or media,  ;
  21.         ;  included but not limited to source listing, facimilie, data  ;
  22.         ;  transmission, cd-rom, or  floppy disk without the expressed  ;
  23.         ;  written consent of the author.                               ;
  24.         ;                                                               ;
  25.         ;  Licence for distribution in commercial use:                  ;
  26.         ;                                                               ;
  27.         ;  Api Software                                                 ;
  28.         ;  12 South Walker Street                                       ;
  29.         ;  Lowell,  MA   01851                                          ;
  30.         ;  508/ 454-4961.                                               ;
  31.         ;                                                               ;
  32.         ;...............................................................;
  33.  
  34.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  35.         ;  Macros                                                       ;
  36.         ;...............................................................;
  37.  
  38. zero                            equ 0
  39. one                             equ 1
  40. two                             equ 2
  41. minusOne                        equ -1
  42. null                            equ 0
  43.  
  44. no                              equ 0
  45. yes                             equ 1
  46.  
  47. false                           equ 0
  48. true                            equ 1
  49.  
  50. __pointer                       equ 0
  51. __segment                       equ 2
  52.  
  53. _pointer                        equ __pointer
  54. _segment                        equ __segment
  55.  
  56. _LOW                            equ _pointer
  57. _HIGH                           equ _segment
  58.  
  59. PARAGRAPH                       equ 16
  60.  
  61. quote                           equ "'"
  62. singleQuote                     equ "'"
  63. doubleQuote                     equ '"'
  64. openBracket                     equ '['
  65. closeBracket                    equ ']'
  66.  
  67. comma                           equ ','
  68. period                          equ '.'
  69. colon                           equ ':'
  70. semicolon                       equ ';'
  71. asterisk                        equ '*'
  72. questionMark                    equ '?'
  73.  
  74.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  75.         ;  Caller's Stack Frame                                         ;
  76.         ;...............................................................;
  77.  
  78. _Flags                          equ 6
  79. _CS                             equ 4
  80. _IP                             equ 2
  81. _ExtraSegment                   equ 0
  82. _DataSegment                    equ -2
  83. _BP                             equ -4
  84. _DI                             equ -6
  85. _SI                             equ -8
  86. _DX                             equ -10
  87. _CX                             equ -12
  88. _BX                             equ -14
  89. _AX                             equ -16
  90. sizeStackFrame                  equ 16
  91.  
  92. RxDOSUserStackPointer           equ 0
  93.  
  94.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  95.         ;  Other Register Definitions.                                  ;
  96.         ;...............................................................;
  97.  
  98. _AL                             equ 00
  99. _AH                             equ 01
  100.  
  101. _BL                             equ 00
  102. _BH                             equ 01
  103.  
  104. _CL                             equ 00
  105. _CH                             equ 01
  106.  
  107. _DL                             equ 00
  108. _DH                             equ 01
  109.  
  110. _SIL                            equ 00
  111. _SIH                            equ 01
  112.  
  113. _DIL                            equ 00
  114. _DIH                            equ 01
  115.  
  116.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  117.         ;  Color.                                                       ;
  118.         ;...............................................................;
  119.  
  120. Black                           equ 00
  121. Blue                            equ 01
  122. Green                           equ 02
  123. Cyan                            equ 03
  124. Magenta                         equ 05
  125. Red                             equ 06
  126. Gray                            equ 07
  127.  
  128. lightBlack                      equ 09
  129. lightBlue                       equ 09
  130. lightGreen                      equ 10
  131. lightCyan                       equ 11
  132. lightRed                        equ 12
  133. lightMagenta                    equ 13
  134. Yellow                          equ 14
  135. White                           equ 15
  136.  
  137.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  138.         ;  Color Define                                                 ;
  139.         ;...............................................................;
  140.  
  141. color   macro foreg, backg
  142.  
  143.     ifb <backg>
  144.         db foreg
  145.         else
  146.         db (backg shl 4) + foreg
  147.         endif
  148.         endm
  149.  
  150.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  151.         ;  Check for Bad Label                                          ;
  152.         ;...............................................................;
  153.         
  154. chklabel    macro label
  155.  
  156.     ifidn <label>,<offset>
  157.         error 'bad label'
  158.         endif
  159.  
  160.     ifidn <label>,<org>
  161.         error 'bad label'
  162.         endif
  163.  
  164.     ifidn <label>,<ptr>
  165.         error 'bad label'
  166.         endif
  167.  
  168.     ifidn <label>,<end>
  169.         error 'bad label'
  170.         endif
  171.  
  172.     ifidn <label>,<endp>
  173.         error 'bad label'
  174.         endif
  175.  
  176.     ifidn <label>,<even>
  177.         error 'bad label'
  178.         endif
  179.  
  180.     ifidn <label>,<segment>
  181.         error 'bad label'
  182.         endif
  183.  
  184.         endm
  185.  
  186.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  187.         ;  Get Double Argument.                                         ;
  188.         ;...............................................................;
  189.         
  190. getdarg  macro seg,reg,label
  191. loadedflag  = no
  192.  
  193.    ifidn <seg>,<es>
  194.         les reg,dword ptr label [bp]
  195.         loadedflag = yes
  196.         endif
  197.  
  198.    ifidn <seg>,<ds>
  199.         lds reg, dword ptr label [bp]
  200.         loadedflag = yes
  201.         endif
  202.  
  203.    ife loadedflag-no
  204.         mov reg, word ptr label [ bp._pointer ]
  205.         mov seg, word ptr label [ bp._segment ]
  206.         endif
  207.         endm
  208.         
  209.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  210.         ;  Get Argument.                                                ;
  211.         ;...............................................................;
  212.         
  213. getarg  macro reg,label
  214.         mov reg,word ptr label [ bp ]
  215.         endm
  216.  
  217.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  218.         ;  Store Double Argument.                                       ;
  219.         ;...............................................................;
  220.         
  221. stordarg  macro label, seg, reg
  222.         mov word ptr label [ bp._pointer ], reg
  223.         mov word ptr label [ bp._segment ], seg
  224.         endm
  225.         
  226.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  227.         ;  Store Argument.                                              ;
  228.         ;...............................................................;
  229.         
  230. storarg macro label, reg
  231.         mov word ptr label [bp], reg
  232.         endm
  233.  
  234.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  235.         ;  Internal Push.                                               ;
  236.         ;...............................................................;
  237.         
  238. tpush   macro reg
  239.     ifidn <reg>, <t>
  240.         pushf
  241.         else
  242.         push reg        
  243.         endif
  244.         endm
  245.  
  246.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  247.         ;  Internal Pop.                                                ;
  248.         ;...............................................................;
  249.         
  250. tpop   macro reg
  251.     ifidn <reg>, <t>
  252.         popf
  253.         else
  254.         pop reg        
  255.         endif
  256.         endm
  257.  
  258.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  259.         ;  Save All Registers.                                          ;
  260.         ;...............................................................;
  261.         
  262. saveAllRegisters macro
  263.  
  264.         push es
  265.         push ds
  266.         push bp
  267.         push di
  268.         push si
  269.         push dx
  270.         push cx
  271.         push bx
  272.         push ax
  273.  
  274.         endm
  275.  
  276.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  277.         ;  Restore All Registers.                                       ;
  278.         ;...............................................................;
  279.         
  280. restoreAllRegisters macro
  281.  
  282.         pop ax
  283.         pop bx
  284.         pop cx
  285.         pop dx
  286.         pop si
  287.         pop di
  288.         pop bp
  289.         pop ds
  290.         pop es
  291.  
  292.         endm
  293.  
  294.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  295.         ;  Save Registers.                                              ;
  296.         ;...............................................................;
  297.         
  298. saveRegisters macro reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  299.    ifnb <reg1>
  300.         tpush reg1
  301.         endif
  302.    ifnb <reg2>
  303.         tpush reg2
  304.         endif
  305.    ifnb <reg3>
  306.         tpush reg3
  307.         endif
  308.    ifnb <reg4>
  309.         tpush reg4
  310.         endif
  311.    ifnb <reg5>
  312.         tpush reg5
  313.         endif
  314.    ifnb <reg6>
  315.         tpush reg6
  316.         endif
  317.    ifnb <reg7>
  318.         tpush reg7
  319.         endif
  320.    ifnb <reg8>
  321.         tpush reg8
  322.         endif
  323.    ifnb <reg9>
  324.         tpush reg9
  325.         endif
  326.    ifnb <reg0>
  327.         tpush reg0
  328.         endif
  329.         endm
  330.  
  331.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  332.         ;  Restore Registers.                                           ;
  333.         ;...............................................................;
  334.         
  335. restoreRegisters macro reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  336.    ifnb <reg1>
  337.         tpop reg1
  338.         endif
  339.    ifnb <reg2>
  340.         tpop reg2
  341.         endif
  342.    ifnb <reg3>
  343.         tpop reg3
  344.         endif
  345.    ifnb <reg4>
  346.         tpop reg4
  347.         endif
  348.    ifnb <reg5>
  349.         tpop reg5
  350.         endif
  351.    ifnb <reg6>
  352.         tpop reg6
  353.         endif
  354.    ifnb <reg7>
  355.         tpop reg7
  356.         endif
  357.    ifnb <reg8>
  358.         tpop reg8
  359.         endif
  360.    ifnb <reg9>
  361.         tpop reg9
  362.         endif
  363.    ifnb <reg0>
  364.         tpop reg0
  365.         endif
  366.         endm
  367.  
  368.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  369.         ;  Save Segments.                                               ;
  370.         ;...............................................................;
  371.         
  372. saveSegments macro reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  373.  
  374.         push ds
  375.         push es
  376.  
  377.    ifnb <reg1>
  378.         tpush reg1
  379.         endif
  380.    ifnb <reg2>
  381.         tpush reg2
  382.         endif
  383.    ifnb <reg3>
  384.         tpush reg3
  385.         endif
  386.    ifnb <reg4>
  387.         tpush reg4
  388.         endif
  389.    ifnb <reg5>
  390.         tpush reg5
  391.         endif
  392.    ifnb <reg6>
  393.         tpush reg6
  394.         endif
  395.    ifnb <reg7>
  396.         tpush reg7
  397.         endif
  398.    ifnb <reg8>
  399.         tpush reg8
  400.         endif
  401.    ifnb <reg9>
  402.         tpush reg9
  403.         endif
  404.    ifnb <reg0>
  405.         tpush reg0
  406.         endif
  407.         endm
  408.  
  409.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  410.         ;  Restore Segments.                                            ;
  411.         ;...............................................................;
  412.         
  413. restoreSegments macro reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  414.  
  415.    ifnb <reg1>
  416.         tpop reg1
  417.         endif
  418.    ifnb <reg2>
  419.         tpop reg2
  420.         endif
  421.    ifnb <reg3>
  422.         tpop reg3
  423.         endif
  424.    ifnb <reg4>
  425.         tpop reg4
  426.         endif
  427.    ifnb <reg5>
  428.         tpop reg5
  429.         endif
  430.    ifnb <reg6>
  431.         tpop reg6
  432.         endif
  433.    ifnb <reg7>
  434.         tpop reg7
  435.         endif
  436.    ifnb <reg8>
  437.         tpop reg8
  438.         endif
  439.    ifnb <reg9>
  440.         tpop reg9
  441.         endif
  442.    ifnb <reg0>
  443.         tpop reg0
  444.         endif
  445.  
  446.         pop es
  447.         pop ds
  448.         endm
  449.  
  450.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  451.         ;  Current Data Segment                                         ;
  452.         ;...............................................................;
  453.  
  454. CurrSegment macro reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  455.  
  456.    ifnb <reg1>
  457.         push cs
  458.         pop reg1
  459.         endif
  460.    ifnb <reg2>
  461.         push cs
  462.         pop reg2
  463.         endif
  464.    ifnb <reg3>
  465.         push cs
  466.         pop reg3
  467.         endif
  468.    ifnb <reg4>
  469.         push cs
  470.         pop reg4
  471.         endif
  472.    ifnb <reg5>
  473.         push cs
  474.         pop reg5
  475.         endif
  476.    ifnb <reg6>
  477.         push cs
  478.         pop reg6
  479.         endif
  480.    ifnb <reg7>
  481.         push cs
  482.         pop reg7
  483.         endif
  484.    ifnb <reg8>
  485.         push cs
  486.         pop reg8
  487.         endif
  488.    ifnb <reg9>
  489.         push cs
  490.         pop reg9
  491.         endif
  492.    ifnb <reg0>
  493.         push cs
  494.         pop reg0
  495.         endif
  496.         endm
  497.  
  498.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  499.         ;  Standard Save                                                ;
  500.         ;...............................................................;
  501.  
  502. saveStandard    macro  reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  503.         push ds
  504.         push es
  505.         push si
  506.         push di
  507.  
  508.    ifnb <reg1>
  509.         tpush reg1
  510.         endif
  511.    ifnb <reg2>
  512.         tpush reg2
  513.         endif
  514.    ifnb <reg3>
  515.         tpush reg3
  516.         endif
  517.    ifnb <reg4>
  518.         tpush reg4
  519.         endif
  520.    ifnb <reg5>
  521.         tpush reg5
  522.         endif
  523.    ifnb <reg6>
  524.         tpush reg6
  525.         endif
  526.    ifnb <reg7>
  527.         tpush reg7
  528.         endif
  529.    ifnb <reg8>
  530.         tpush reg8
  531.         endif
  532.    ifnb <reg9>
  533.         tpush reg9
  534.         endif
  535.    ifnb <reg0>
  536.         tpush reg0
  537.         endif
  538.         endm
  539.  
  540.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  541.         ;  Standard Restore                                             ;
  542.         ;...............................................................;
  543.  
  544. restoreStandard macro  reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  545.  
  546.    ifnb <reg1>
  547.         tpop reg1
  548.         endif
  549.    ifnb <reg2>
  550.         tpop reg2
  551.         endif
  552.    ifnb <reg3>
  553.         tpop reg3
  554.         endif
  555.    ifnb <reg4>
  556.         tpop reg4
  557.         endif
  558.    ifnb <reg5>
  559.         tpop reg5
  560.         endif
  561.    ifnb <reg6>
  562.         tpop reg6
  563.         endif
  564.    ifnb <reg7>
  565.         tpop reg7
  566.         endif
  567.    ifnb <reg8>
  568.         tpop reg8
  569.         endif
  570.    ifnb <reg9>
  571.         tpop reg9
  572.         endif
  573.    ifnb <reg0>
  574.         tpop reg0
  575.         endif
  576.  
  577.         pop di
  578.         pop si
  579.         pop es
  580.         pop ds
  581.         endm
  582.  
  583.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  584.         ;  Set Seg Register                                             ;
  585.         ;...............................................................;
  586.  
  587. setSeg  macro seg, reg
  588.  
  589.     segcopied = no
  590.  
  591.     irp treg, <es, ds, cs, ss>
  592.       ifidn <reg>, <treg>
  593.         segcopied = yes
  594.         push reg
  595.         pop seg
  596.         endif
  597.         endm
  598.  
  599.     ife (segcopied NE no)
  600.         mov seg, reg
  601.         endif
  602.  
  603.         endm
  604.  
  605.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  606.         ;  Set DS                                                       ;
  607.         ;...............................................................;
  608.  
  609. setDS   macro reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  610.  
  611.    ifnb <reg1>
  612.         setSeg ds, reg1
  613.         endif
  614.    ifnb <reg2>
  615.         setSeg ds, reg2
  616.         endif
  617.    ifnb <reg3>
  618.         setSeg ds, reg3
  619.         endif
  620.    ifnb <reg4>
  621.         setSeg ds, reg4
  622.         endif
  623.    ifnb <reg5>
  624.         setSeg ds, reg5
  625.         endif
  626.    ifnb <reg6>
  627.         setSeg ds, reg6
  628.         endif
  629.    ifnb <reg7>
  630.         setSeg ds, reg7
  631.         endif
  632.    ifnb <reg8>
  633.         setSeg ds, reg8
  634.         endif
  635.    ifnb <reg9>
  636.         setSeg ds, reg9
  637.         endif
  638.    ifnb <reg0>
  639.         setSeg ds, reg0
  640.         endif
  641.         endm
  642.  
  643.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  644.         ;  Set ES                                                       ;
  645.         ;...............................................................;
  646.  
  647. setES   macro reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  648.  
  649.    ifnb <reg1>
  650.         setSeg es, reg1
  651.         endif
  652.    ifnb <reg2>
  653.         setSeg es, reg2
  654.         endif
  655.    ifnb <reg3>
  656.         setSeg es, reg3
  657.         endif
  658.    ifnb <reg4>
  659.         setSeg es, reg4
  660.         endif
  661.    ifnb <reg5>
  662.         setSeg es, reg5
  663.         endif
  664.    ifnb <reg6>
  665.         setSeg es, reg6
  666.         endif
  667.    ifnb <reg7>
  668.         setSeg es, reg7
  669.         endif
  670.    ifnb <reg8>
  671.         setSeg es, reg8
  672.         endif
  673.    ifnb <reg9>
  674.         setSeg es, reg9
  675.         endif
  676.    ifnb <reg0>
  677.         setSeg es, reg0
  678.         endif
  679.         endm
  680.  
  681.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  682.         ;  Set SS                                                       ;
  683.         ;...............................................................;
  684.  
  685. setSS   macro reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg0
  686.  
  687.    ifnb <reg1>
  688.         setSeg ss, reg1
  689.         endif
  690.    ifnb <reg2>
  691.         setSeg ss, reg2
  692.         endif
  693.    ifnb <reg3>
  694.         setSeg ss, reg3
  695.         endif
  696.    ifnb <reg4>
  697.         setSeg ss, reg4
  698.         endif
  699.    ifnb <reg5>
  700.         setSeg ss, reg5
  701.         endif
  702.    ifnb <reg6>
  703.         setSeg ss, reg6
  704.         endif
  705.    ifnb <reg7>
  706.         setSeg ss, reg7
  707.         endif
  708.    ifnb <reg8>
  709.         setSeg ss, reg8
  710.         endif
  711.    ifnb <reg9>
  712.         setSeg ss, reg9
  713.         endif
  714.    ifnb <reg0>
  715.         setSeg ss, reg0
  716.         endif
  717.         endm
  718.  
  719.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  720.         ;  Adds an offset to a seg register pair                        ;
  721.         ;...............................................................;
  722.  
  723. offsetAddr macro seg, reg, offs
  724.         local no_ovf
  725.         segspecial = no
  726.         add reg, offs
  727.         jnc no_ovf
  728.  
  729.      irp treg, <es, ds, cs, ss>
  730.       ifidn <seg>, <treg>
  731.         segspecial = yes
  732.         mov ax, seg
  733.         add ax, 1000h                           ; account for carry
  734.         mov seg, ax
  735.         endif
  736.         endm
  737.  
  738.      ife segspecial-no                          ; if seg register not special
  739.         add seg, 1000h                          ; account for carry
  740.         endif
  741.  
  742. no_ovf:
  743.         endm
  744.  
  745.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  746.         ;  Defines a standard subr entry point                          ;
  747.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  748.         ;                                                               ;
  749.         ;  saves bp and sets bp to value of sp at entry.                ;
  750.         ;  Must use Return macro to exit.                               ;
  751.         ;                                                               ;
  752.         ;...............................................................;
  753.  
  754. Entry   macro __args                            ; # word entries
  755.  
  756.         push bp                                 ; save bp
  757.         mov bp,sp                               ; set bp to point to stack
  758.  
  759.         _defEntry = 0
  760.         _maxArgs  = 0
  761.  
  762.     ifnb <__args>
  763.         _retEntry = __args
  764.         _maxArgs  = 2 * __args
  765.         _argEntry = 2 * __args + 4              ; assumes NEAR
  766.     else    
  767.         _retEntry = 0
  768.         _argEntry = 4                           ; assumes NEAR
  769.         endif
  770.         endm
  771.  
  772.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  773.         ;  Defines a standard subr far entry point                      ;
  774.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  775.         ;                                                               ;
  776.         ;  saves bp and sets bp to value of sp at entry.                ;
  777.         ;  Must use Return macro to exit.                               ;
  778.         ;                                                               ;
  779.         ;...............................................................;
  780.  
  781. FarEntry        macro __args                    ; word entries
  782.  
  783.         push bp                                 ; save bp
  784.         mov bp,sp                               ; set bp to point to stack
  785.  
  786.         _defEntry = 0
  787.         _maxArgs  = 0
  788.  
  789.     ifnb <__args>
  790.         _retEntry = __args
  791.         _maxArgs  = 2 * __args
  792.         _argEntry = 2 * __args + 6              ; assumes FAR
  793.     else    
  794.         _retEntry = 0
  795.         _argEntry = 6                           ; assumes FAR
  796.         endif
  797.         endm
  798.  
  799.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  800.         ;  Special Entry does not alter registers                       ;
  801.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  802.         ;                                                               ;
  803.         ;  ...but sets argument parameters.                             ;
  804.         ;  Must use Return macro to exit.                               ;
  805.         ;                                                               ;
  806.         ;...............................................................;
  807.  
  808. SpecialEntry  macro __args                      ; word entries
  809.  
  810.         _defEntry  = 0
  811.         _maxArgs   = 0
  812.  
  813.     ifnb <__args>
  814.         _retEntry = __args
  815.         _maxArgs  = 2 * __args
  816.         _argEntry = 2 * __args + 4              ; (no bp pushed )
  817.     else    
  818.         _retEntry = 0
  819.         _argEntry = 4                           ; assumes FAR
  820.         endif
  821.         endm
  822.  
  823. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  824. ;  
  825. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  826.  
  827. Arg     macro arg_name
  828.  
  829.     if ( _maxArgs LT 2 )
  830.         error 'Arg definition does not match Entry'
  831.         endif
  832.  
  833.     ifb <arg_name>
  834.         error 'Arg must have an arg_name parameter.'
  835.         endif
  836.  
  837.         _argEntry = _argEntry - 2
  838.         arg_name  = _argEntry
  839.         chklabel arg_name        
  840.         endm
  841.  
  842. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  843. ;  
  844. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  845.  
  846. DArg    macro arg_name
  847.  
  848.     if ( _maxArgs LT 4 )
  849.         error 'Arg definition does not match Entry'
  850.         endif
  851.  
  852.     ifb <arg_name>
  853.         error 'Arg must have an arg_name parameter.'
  854.         endif
  855.  
  856.         _argEntry = _argEntry - 4
  857.         arg_name  = _argEntry
  858.         chklabel arg_name        
  859.         endm
  860.  
  861. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  862. ;  
  863. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  864.  
  865. Def     macro arg_name, reg
  866.  
  867.     ifb <arg_name>
  868.         error 'Def must have an arg_name parameter.'
  869.         endif
  870.  
  871.         _defEntry = _defEntry - 2
  872.         arg_name  = _defEntry
  873.  
  874. pushedreg = no
  875.  
  876.     ifb <reg>
  877.         push ax
  878.         pushedreg = yes
  879.         endif
  880.  
  881.     ifnb <reg>
  882.      irp treg,<ax,bx,cx,dx,bp,si,di,es,ds,ss,cs,f>
  883.       ifidn <reg>,<treg>
  884.         tpush reg
  885.         pushedreg = yes
  886.         endif
  887.         endm
  888.         endif
  889.  
  890.      ife pushedreg-no                           ; if not pushed
  891.         push ax
  892.         mov word ptr arg_name [bp],reg          ; really a value.
  893.         endif
  894.         chklabel arg_name
  895.         endm
  896.  
  897. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  898. ;  
  899. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  900.  
  901. DDef    macro arg_name, seg, reg
  902.  
  903.     ifb <arg_name>
  904.         error 'Def must have an arg_name parameter.'
  905.         endif
  906.  
  907. _defEntry       = _defEntry - 4
  908. arg_name        = _defEntry
  909.  
  910. pushedreg       = no
  911. pushedseg       = no
  912.  
  913.     ifb <seg>
  914.         push ax
  915.         push ax
  916.         pushedseg = yes
  917.         pushedreg = yes
  918.         endif
  919.  
  920.     ifnb <seg>
  921.      irp tseg,<ax,bx,cx,dx,bp,si,di,es,ds,ss,cs,f>
  922.       ifidn <seg>,<tseg>
  923.         tpush seg
  924.         pushedseg = yes
  925.         endif
  926.         endm
  927.         endif
  928.  
  929.      ife pushedseg-no                           ; if not pushed
  930.         push ax
  931.         mov word ptr arg_name [bp],seg          ; really a value.
  932.         endif
  933.  
  934.     ifnb <reg>
  935.      irp treg,<ax,bx,cx,dx,bp,si,di,es,ds,ss,cs,f>
  936.       ifidn <reg>,<treg>
  937.         tpush reg
  938.         pushedreg = yes
  939.         endif
  940.         endm
  941.  
  942.      ife pushedreg-no                           ; if not pushed (while reg not blank)
  943.         push ax
  944.         mov word ptr arg_name [bp+2],reg
  945.         endif
  946.  
  947.         else
  948.         ife pushedseg-no                        ; if not pushed
  949.           push ax ;
  950.           endif
  951.         endif
  952.         endm
  953.  
  954. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  955. ;  Define Words
  956. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  957.  
  958. DefWords macro arg_name, size
  959.  
  960.     ifb <arg_name>
  961.         error 'Def must have an arg_name parameter.'
  962.         endif
  963.  
  964. ?tempSize       = ( 2 * size )
  965. _defEntry       = _defEntry - ?tempSize
  966. arg_name        = _defEntry
  967.  
  968.         sub sp, ?tempSize
  969.         endm
  970.         
  971. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  972. ;  Define Bytes
  973. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  974. DefBytes macro arg_name, size
  975.  
  976.     ifb <arg_name>
  977.         error 'Def must have an arg_name parameter.'
  978.         endif
  979.  
  980. ?tempSize       = ((size + 1) AND 0FFFEh)
  981. _defEntry       = _defEntry - ?tempSize
  982. arg_name        = _defEntry
  983.  
  984.         sub sp, ?tempSize
  985.         endm
  986.         
  987. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  988. ;  Create A Variable Reference, but you must do the push
  989. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  990.  
  991. Temp    macro arg_name
  992.  
  993.     ifb <arg_name>
  994.         error 'Temp must have an arg_name parameter.'
  995.         endif
  996.  
  997.         _defEntry = _defEntry - 2
  998.         arg_name  = _defEntry
  999.         endm
  1000.  
  1001. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  1002. ;  
  1003. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  1004.  
  1005. DTemp   macro arg_name
  1006.  
  1007.     ifb <arg_name>
  1008.         error 'Def must have an arg_name parameter.'
  1009.         endif
  1010.  
  1011.         _defEntry = _defEntry - 4
  1012.         arg_name  = _defEntry
  1013.         endm
  1014.  
  1015. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  1016. ;  
  1017. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  1018.  
  1019. Return  macro
  1020.         mov sp, bp
  1021.         pop bp
  1022.         ret (2 * _retEntry)
  1023.         endm
  1024.  
  1025.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1026.         ;  Set Error                                                    ;
  1027.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  1028.         ;                                                               ;
  1029.         ;  sets carry,                                                  ;
  1030.         ;  loads an error value into ax,                                ;
  1031.         ;  optionally jumps to an address.                              ;
  1032.         ;                                                               ;
  1033.         ;...............................................................;
  1034.  
  1035. SetError macro errcode, opt_jumpto
  1036.         stc
  1037.         mov ax, errcode
  1038.  
  1039.     ifnb < opt_jumpto >
  1040.         jmp opt_jumpto
  1041.         endif
  1042.         endm
  1043.  
  1044. iferror macro errcode, opt_jumpto
  1045.         local label
  1046.         
  1047.     ifb < opt_jumpto >
  1048.         error 'must have a goto label'
  1049.         else
  1050.         jnc label
  1051.         mov ax, errcode
  1052.         jmp opt_jumpto
  1053.  
  1054. label:
  1055.         endif
  1056.         endm
  1057.  
  1058.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1059.         ;  Internal Int28 Emulation call                                ;
  1060.         ;...............................................................;
  1061.  
  1062. Int28   macro
  1063.  
  1064.         pushf
  1065.         call _Interrupt_28
  1066.         endm
  1067.  
  1068.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1069.         ;  Compare and Goto                                             ;
  1070.         ;...............................................................;
  1071.  
  1072. Goto            macro value, loc
  1073.         cmp al, value
  1074.         jz loc 
  1075.  
  1076.         endm
  1077.  
  1078.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1079.         ;  Long Cond Jumps (ifCarry, ifNCarry)                          ;
  1080.         ;...............................................................;
  1081.  
  1082. ifc     macro addr
  1083.         local label
  1084.         jnc label
  1085.         jmp addr
  1086.  
  1087. label:
  1088.         endm
  1089.  
  1090. ifnc    macro addr
  1091.         local label
  1092.         jc label
  1093.         jmp addr
  1094.  
  1095. label:
  1096.         endm
  1097.  
  1098. ifz     macro addr
  1099.         local label
  1100.         jnz label
  1101.         jmp addr
  1102.  
  1103. label:
  1104.         endm
  1105.  
  1106. ifnz    macro addr
  1107.         local label
  1108.         jz label
  1109.         jmp addr
  1110.  
  1111. label:
  1112.         endm
  1113.  
  1114.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1115.         ;  Normalize Seg and Offset                                     ;
  1116.         ;...............................................................;
  1117.  
  1118. NormalizeBuffer macro seg, offset
  1119.  
  1120.         push offset
  1121.         shr offset, 1
  1122.         shr offset, 1
  1123.         shr offset, 1
  1124.         shr offset, 1
  1125.  
  1126.         push ax
  1127.         mov ax, seg
  1128.         add ax, offset
  1129.         mov seg, ax
  1130.         pop ax
  1131.  
  1132.         pop offset
  1133.         and offset, 000fh
  1134.         endm
  1135.  
  1136.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1137.         ;  Clear Memory                                                 ;
  1138.         ;...............................................................;
  1139.  
  1140. clearMemory     macro size
  1141.  
  1142.     ife size
  1143.         error 'Cannot support illegal size'
  1144.         else
  1145.  
  1146.         push di
  1147.         push cx
  1148.         push ax
  1149.         xor ax, ax
  1150.  
  1151.     ife (size AND 1)
  1152.         mov cx, (size)/2
  1153.         rep movsw
  1154.         else
  1155.  
  1156.         mov cx, size
  1157.         rep movsb
  1158.         endif
  1159.  
  1160.         pop ax
  1161.         pop cx
  1162.         pop di
  1163.         endif
  1164.         endm
  1165.  
  1166.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1167.         ;  32 Bit Divide                                                ;
  1168.         ;...............................................................;
  1169.  
  1170.      ;  mov bx, dx
  1171.      ;  xchg ax, bx
  1172.      ;  xor dx, dx
  1173.      ;  div cx
  1174.      ;
  1175.      ;  xchg ax, bx
  1176.      ;  div cx
  1177.      ;  (remainder in dx)
  1178.      ;
  1179.  
  1180.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1181.         ;  Fast Move                                                    ;
  1182.         ;...............................................................;
  1183.  
  1184. fastmove        macro arg1, arg2                ; args not used
  1185.         local label
  1186.         shr cx, 1                               ; optimize for words
  1187.         rep movsw                               ; move them
  1188.         jnc label                               ; even bytes -->
  1189.         movsb                                   ; move odd byte
  1190.  
  1191. label:
  1192.         endm
  1193.  
  1194.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1195.         ;  Return Called Stack Frame                                    ;
  1196.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  1197.         ;                                                               ;
  1198.         ;  reg defined contains stack reference at current Int 21.      ;
  1199.         ;                                                               ;
  1200.         ;...............................................................;
  1201.  
  1202. RetCallersStackFrame macro seg, reg
  1203.  
  1204.     ifb < seg >
  1205.         error "must have both seg and reg"
  1206.         exitm
  1207.         endif
  1208.         
  1209.     ifb < reg >
  1210.         error "must have both seg and reg"
  1211.         exitm
  1212.         endif
  1213.  
  1214.     ifidn <seg>,<ss>
  1215.         error "can't seg change to ss"
  1216.         exitm
  1217.  
  1218.         else
  1219.         call _RetCallersStackFrame
  1220.         pop reg
  1221.         pop seg
  1222.  
  1223.         endif
  1224.         endm
  1225.  
  1226.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1227.         ;  Reserve Stack Space (in case interrupt/recall)               ;
  1228.         ;...............................................................;
  1229.  
  1230. ReserveStack    macro value
  1231.  
  1232.         cli
  1233.         sub word ptr cs:[ _RxDOS_CurrentStackTop ], value
  1234.  
  1235.         sti
  1236.         endm
  1237.  
  1238.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1239.         ;  Define Command                                               ;
  1240.         ;...............................................................;
  1241.  
  1242. Cmnd    macro loc, asciz1, asciz2, asciz3, asciz4, asciz5, asciz6
  1243.  
  1244.         dw loc
  1245.         db asciz1, 0
  1246.         endm
  1247.  
  1248.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1249.         ;  Define Switches                                              ;
  1250.         ;...............................................................;
  1251.  
  1252. Switch  macro letter, flags, min, max, value
  1253.  
  1254.     ifb <letter>
  1255.         db -1
  1256.     else    
  1257.      ifb <flags>
  1258.         db letter
  1259.         dw 00, 0000, 0000, 0000
  1260.     else    
  1261.      ifb <min>
  1262.         db letter
  1263.         dw flags, 0000, 0000, 0000
  1264.     else    
  1265.      ifb <max>
  1266.         db letter
  1267.         dw flags, min,  0000, 0000
  1268.     else    
  1269.      ifb <value>
  1270.         db letter
  1271.         dw flags, min,  max,  0000
  1272.     else    
  1273.         db letter
  1274.         dw flags, min,  max,  value
  1275.         endif
  1276.         endif
  1277.         endif
  1278.         endif
  1279.         endif
  1280.         endm
  1281.  
  1282.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  1283.         ;  Asciz                                                        ;
  1284.         ;...............................................................;
  1285.  
  1286. Asciz   macro arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
  1287.  
  1288.     ifnb <arg1>
  1289.         db arg1
  1290.         endif
  1291.  
  1292.     ifnb <arg2>
  1293.         db arg2
  1294.         endif
  1295.  
  1296.     ifnb <arg3>
  1297.         db arg3
  1298.         endif
  1299.  
  1300.     ifnb <arg4>
  1301.         db arg4
  1302.         endif
  1303.  
  1304.     ifnb <arg5>
  1305.         db arg5
  1306.         endif
  1307.  
  1308.     ifnb <arg6>
  1309.         db arg6
  1310.         endif
  1311.  
  1312.     ifnb <arg7>
  1313.         db arg7
  1314.         endif
  1315.  
  1316.     ifnb <arg8>
  1317.         db arg8
  1318.         endif
  1319.  
  1320.     ifnb <arg9>
  1321.         db arg9
  1322.         endif
  1323.  
  1324.         db 0
  1325.         endm
  1326.